#include "comm.hpp"
#include <unistd.h>

int main()
{
    key_t k = getKey();
    printf("0x%x\n",k);
     int shmid = getShm(k);
    printf("shmid : %d\n",shmid);

    sleep(5);

    char *start = (char*)attachShm(shmid);
    printf("attach success, addrees start: %p\n",start);

    const char* message = " hello server, 我是另外一个进程,正在和你通信";
    pid_t id =getpid();
    int cnt = 1;
    // char buffer[1024];这是普通的写法 共享内存不需要

    // done
    while(true)
    {
        //sleep(1);
        
        sleep(5);
        snprintf(start,MAX_SIZE,"%s[pid:%d][消息编号:%d]",message,id,cnt++);
        // snprintf(buffer,sizeof(buffer),"%s[pid:%d][消息编号:%d]", message, id, cnt++);
        // memcpy(start,buffer,strlen(buffer)+1);
        // pid count message

    }

    detachShm(start);



    //delShm(shmid);
    return 0;
}